package com.neusoft.yuejian_6.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian_6.activity.TrainDetailActivity;
import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.javabean.Train;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Mao on 2017/9/26.
 */

public class TrainAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContex;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public TrainAdapter(Context mContext, List mDataList) {
        this.mContex =  mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_train, parent, false);
        return new ViewHolder(v);
    }



    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Train entity = (Train) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
     //   viewHolder.food_level.setRating(entity.getLevel());
        viewHolder.train_name.setText(entity.getTrain_name());
       // System.out.print("Train_name");
        String train_pic = "http://10.0.2.2/neu1_yuejian/Public/Admin/photo/"+entity.getTrain_pic();
        System.out.print("train_pic");
        if (!train_pic.equals("")) {
            Picasso.with(mContex).load(train_pic).into(viewHolder.train_pic);
        }
       // Picasso.with(mContex).load(entity.getTrain_id_id()).into(viewHolder.Train_pic);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putInt("train_id", entity.getTrain_id());
                bundle.putString("train_name", entity.getTrain_name());
             bundle.putString("train_intro", entity.getTrain_intro());
                bundle.putString("train_address", entity.getTrain_address());
               bundle.putString("train_phone", entity.getTrain_phone());
                bundle.putString("train_pic", entity.getTrain_pic());
                Intent intent=new Intent(mContex, TrainDetailActivity.class);
                intent.putExtras(bundle);
                mContex.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
       return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
       // ImageView food_thumb;
        TextView train_name;
        ImageView train_pic;
        //RatingBar food_level;

        public ViewHolder(View itemView) {
            super(itemView);
            train_name = (TextView) itemView.findViewById(R.id.train_name);
            train_pic = (ImageView) itemView.findViewById(R.id.train_pic);
         //   food_thumb = (ImageView) itemView.findViewById(R.id.food_thumb);
           // food_info = (TextView) itemView.findViewById(R.id.food_info);
           // food_level = (RatingBar) itemView.findViewById(R.id.food_level);
        }
    }
}